﻿using System.Collections.Generic;
using System.Xml;

namespace MockingBird.Simulator.Framework.Configuration
{
    /// <summary>
    /// contains all the application level configuration settings.
    /// </summary>
    public class ApplicationConfiguration
    {
        private IConfigurationDataProvider configProvider;
        private XmlDocument globalConfigXmlDoc;
        private Dictionary<string, string> settingsDictionary;

        public ApplicationConfiguration(IConfigurationDataProvider configurationDataProvider)
        {
            this.configProvider = configurationDataProvider;
            settingsDictionary = new Dictionary<string, string>();
            InitializeGlobalConfiguration();
        }

        public string ConfigurationFilesRoot
        {
            get
            {
                return this.configProvider.ConfigurationFilesRoot;
            }
        }

        public string AppRoot
        {
            get
            {
                return settingsDictionary["AppRoot"];
            }
        }

        public string DataFilesRoot
        {
            get
            {
                return settingsDictionary["DataFilesRoot"];
            }
        }

        public string EndpointsRoot
        {
            get
            {
                return settingsDictionary["EndpointsRoot"];
            }
        }

        public string LogFilesRoot
        {
            get
            {
                return settingsDictionary["LogFilesRoot"];
            }
        }

        public string ConfigSchemaFilesLocation
        {
            get
            {
                return settingsDictionary["ConfigSchemaFilesLocation"];
            }
        }

        public string TimeoutForce
        {
            get
            {
                return settingsDictionary["TimeoutForce"];
            }
        }

        public string GetResponseRootForEndpoint(string endpointName)
        {
            return this.configProvider.GetResponseRoot(endpointName);
        }

        public string GetEndpointConfigFile(string endpointName)
        {
            return this.configProvider.GetConfigFile(endpointName, this.AppRoot);
        }

        public HandlerMapInfo GetHandlerMapInfo()
        {
            return this.configProvider.GetHandlerMapInfo();
        }

        public HandlerRegistrationInfo GetHandlerRegistrationInfo()
        {
            return this.configProvider.GetHandlerRegistrationInfo();
        }

        public void AddHandlerMapEntry(HandlerMapEntry mapEntry)
        {
            this.configProvider.AddHandlerMapEntry(mapEntry);
        }

        private void InitializeGlobalConfiguration()
        {
            settingsDictionary = this.configProvider.GetGlobalSettings();


        }

        public List<string> GetRegisteredEndpoints()
        {
            return this.configProvider.GetRegisteredEndpoints();
        }

    }
}
